/**
  ******************************************************************************
  * @file    BSP_adc.h
  * @author  Silan - MC Team
  * @version 1.0.0
  * @date    2017/07/19
  * @brief   ADC Related Config Header File
  * @details None
	* @note    None
  ******************************************************************************
  * @attention
  * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
  * AS A RESULT, SILAN MICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
  * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
  * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
  * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
	*
  ******************************************************************************
	* Change History
	* -# 2017/07/19 | v1.0.0 | Wangjianlong | Creat file.
	*
	******************************************************************************
  */

/*******************************************************************************
 * Define to prevent recursive inclusion
 ******************************************************************************/
#ifndef __BSP_ADC_H__
#define __BSP_ADC_H__

/*******************************************************************************
 * Include section
 ******************************************************************************/
#include "stdint.h"
#include "SC32F58128_adc.h"
#include "IQmathlib.h"
#include "basic_fun.h"

#include "GlobalInclude.h"

#include "BSP_gpio.h"

/*******************************************************************************
 * Constants and macros
 ******************************************************************************/

/* ADC channel definitions */
#define  MAX_AD_CHNL        16
#define  PFC_AD_CHNL        4
#define  PMSM_AD_CHNL       3
#define  FAN_AD_CHNL        3
#define  AC_CTRL_AD_CHNL   (MAX_AD_CHNL - PFC_AD_CHNL - PMSM_AD_CHNL - FAN_AD_CHNL)

#define  IUN_AD_CHNL      0   // ADCINA0
#define  IUN_FAN_CHNL     1   // ADCINA1
#define  IAC_AD_CHNL      2   // ADCINA2
#define  AIR_AD_CHNL      3   // ADCINA3
#define  DISCRG_AD_CHNL   4   // ADCINA4
#define  RSDA5_AD_CHNL    5   // ADCINA5
#define  COIL_AD_CHNL     6   // ADCINA6
#define  SUCK_AD_CHNL     7   // ADCINA7
#define  IPM_AD_CHNL      8   // ADCINB0
#define  VDC_AD_CHNL      9   // ADCINB1
#define  IPM_SEL_CHNL    10   // ADCINB2(not used)
#define  IVN_FAN_CHNL    11   // ADCINB3
#define  FIPM_AD_CHNL    12   // ADCINB4
#define  RSDB5_AD_CHNL   13   // ADCINB5
#define  RSDB6_AD_CHNL   14   // ADCINB6
#define  VAC_AD_CHNL     15   // ADCINB7

#define  ADCSOC0_CHNL     IUN_AD_CHNL
#define  ADCSOC1_CHNL     IUN_AD_CHNL
#define  ADCSOC2_CHNL     IUN_AD_CHNL
#define  ADCSOC3_CHNL     IUN_FAN_CHNL
#define  ADCSOC4_CHNL     IVN_FAN_CHNL
#define  ADCSOC5_CHNL     IUN_FAN_CHNL
#define  ADCSOC6_CHNL     IAC_AD_CHNL
#define  ADCSOC7_CHNL     VAC_AD_CHNL
#define  ADCSOC8_CHNL     VDC_AD_CHNL
#define  ADCSOC9_CHNL     VDC_AD_CHNL // overlap enable needed
#define  ADCSOC10_CHNL    IPM_AD_CHNL//FIPM_AD_CHNL//
#define  ADCSOC11_CHNL    SUCK_AD_CHNL
#define  ADCSOC12_CHNL    DISCRG_AD_CHNL
#define  ADCSOC13_CHNL    AIR_AD_CHNL
#define  ADCSOC14_CHNL    COIL_AD_CHNL
#define  ADCSOC15_CHNL    COIL_AD_CHNL // overlap enable needed

/*******************************************************************************
 * Typedefs, structs and enums
 ******************************************************************************/
/**
  *@brief  ADC sample sequency struct range from high priority to low
  */
struct ADNAME
{
  _iq  IUN_AD;        ///< chnl 0 ad
  _iq  IVN_AD;        ///< chnl 1 ad
  _iq  IWN_AD;        ///< chnl 2 ad
  _iq  IUN_FAN_AD;    ///< chnl 3 ad
  _iq  IVN_FAN_AD;    ///< chnl 4 ad
  _iq  IWN_FAN_AD;    ///< chnl 5 ad
  _iq  IAC_AD;        ///< chnl 6 ad
  _iq  VAC_AD;        ///< chnl 7 ad
  _iq  VDC_AD;        ///< chnl 8 ad
  _iq  RSD1_AD;       ///< chnl 9 ad
  _iq  FIPM_AD;       ///< chnl 10 ad
  _iq  SUCK_AD;       ///< chnl 11 ad
  _iq  DISCHARGE_AD;  ///< chnl 12 ad
  _iq  AIR_AD;        ///< chnl 13 ad
  _iq  COIL_AD;       ///< chnl 14 ad
  _iq  RSD2_AD;       ///< chnl 15 ad
};

/**
  *@brief  ADC sample sequency union range from high priority to low
  */
union ADSMP
{
  struct ADNAME  AD;                ///< AD chanel setting
  _iq            IQAd[MAX_AD_CHNL]; ///< get AD data
};


enum ADC_SMP_GROUP_e
{
  ADC_SMP_GRP_PFC = 0,   ///< ADC result for PFC control
  ADC_SMP_GRP_PMSM,      ///< ADC result for PMSM control
  ADC_SMP_GRP_FAN,       ///< ADC result for FAN control
  ADC_SMP_GRP_AC,        ///< ADC result for air condition control
};

/*******************************************************************************
 * Variables
 ******************************************************************************/
extern union ADSMP g_uAdSmp;

/*******************************************************************************
 * Prototypes of the functions
 ******************************************************************************/
extern void BSP_AdcConfig(void);
extern uint8_t GetSmpData(enum ADC_SMP_GROUP_e Num);

/*---------------------------------- End of the file ---------------------------------*/
#endif /* __BSP_ADC_H__ */

